ostree-prepare-root: add option processing for kernel arguments
authorJoseph Marrero Corchado <jmarrero@redhat.com>
Thu, 29 May 2025 18:48:50 +0000 (14:48 -0400)
committerJoseph Marrero Corchado <jmarrero@redhat.com>
Thu, 29 May 2025 21:05:13 +0000 (17:05 -0400)
In a future soft-reboot feature this will allow us to pass kernel
arguments for the deployment we are going to soft-reboot into.

src/switchroot/ostree-prepare-root.c

index 68707f1064f42d7f0891cb473666293c13b6575f..1e77809f1b44e8556caa7a440593345f59656961 100644 (file)
@@ -97,6 +97,8 @@
 
 #include "ostree-mount-util.h"
 
+static GOptionEntry options[] = { { NULL } };
+
 static bool
 sysroot_is_configured_ro (const char *sysroot)
 {
@@ -261,11 +263,26 @@ main (int argc, char *argv[])
   struct stat stbuf;
   g_autoptr (GError) error = NULL;
 
+  g_autoptr (GOptionContext) context = g_option_context_new ("SYSROOT [KERNEL_CMDLINE]");
+  g_option_context_add_main_entries (context, options, NULL);
+  if (!g_option_context_parse (context, &argc, &argv, &error))
+    errx (EXIT_FAILURE, "Error parsing options: %s", error->message);
+
   if (argc < 2)
-    err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT");
+    err (EXIT_FAILURE, "usage: ostree-prepare-root SYSROOT [KERNEL_CMDLINE]");
   const char *root_arg = argv[1];
 
-  g_autofree char *kernel_cmdline = read_proc_cmdline ();
+  g_autofree char *kernel_cmdline = NULL;
+  if (argc < 3)
+    {
+      kernel_cmdline = read_proc_cmdline ();
+    }
+  else
+    {
+      // Duplicate argv[2] so g_autofree can safely manage it.
+      kernel_cmdline = g_strdup (argv[2]);
+    }
+
   if (!kernel_cmdline)
     errx (EXIT_FAILURE, "Failed to read kernel cmdline");